import mongoose from '../config/DBHelper'
import moment from 'moment'
const Schema = mongoose.Schema
const MenusSchema = new Schema({
  title: { type: String, default: '' },
  path: { type: String, default: '' },
  component: { type: String, default: '' },
  hideInBread: { type: Boolean, default: false },
  hideInMenu: { type: Boolean, default: false },
  notCache: { type: Boolean, default: false },
  icon: { type: String, default: '' },
  sort: { type: String, default: 0 },
  redirect: { type: String, default: '' },
  type: { type: String, default: 'menu' },
  expand: { type: Boolean, default: true }
})

const OperationsSchema = new Schema({
  name: { type: String, defalut: '' },
  type: { type: String, defalut: '' },
  method: { type: String, defalut: '' },
  path: { type: String, defalut: '' },
  remark: { type: String, defalut: '' }
})

MenusSchema.add({
  children: [MenusSchema],
  operations: [OperationsSchema]
})

MenusSchema.pre('save', function (next) {
  this.created = moment().format('YYYY-MM-DD HH:mm:ss')
  next()
})

const Menus = mongoose.model('menus', MenusSchema)

export default Menus
